package cn.edu.baiyunu.myapplication.ui.screens.add

import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

/**
 * 添加交易的ViewModel
 */
class AddTransactionViewModel : ViewModel() {

    // UI状态
    private val _uiState = MutableStateFlow(AddTransactionUiState())
    val uiState: StateFlow<AddTransactionUiState> = _uiState.asStateFlow()

    // 设置交易类型
    fun setTransactionType(type: TransactionType) {
        _uiState.update { it.copy(transactionType = type) }
    }

    // 设置金额
    fun setAmount(amount: String) {
        _uiState.update { it.copy(amount = amount) }
    }

    // 设置备注
    fun setNote(note: String) {
        _uiState.update { it.copy(note = note) }
    }

    // 设置分类
    fun setCategory(category: Category) {
        _uiState.update { it.copy(selectedCategory = category) }
    }
}

/**
 * 添加交易UI状态数据类
 */
data class AddTransactionUiState(
    val transactionType: TransactionType = TransactionType.EXPENSE,
    val amount: String = "",
    val date: String = "今天",
    val selectedCategory: Category? = null,
    val note: String = ""
) 